//
//  RattanCityPicker.h
//  CityPicker
//
//  Created by rattanchen on 18/8/9.
//  Copyright © 2017年 rattanchen. All rights reserved.
//

#import "RattanCityPicker.h"
#import "Helper.h"
#define PROVINCE_COMPONENT  0
#define CITY_COMPONENT      1
#define DISTRICT_COMPONENT  2
#define KScreenWidth  [UIScreen mainScreen].bounds.size.width
#define KScreenHeight  [UIScreen mainScreen].bounds.size.height

@interface RattanCityPicker()

//省数组
@property NSArray *arrProvince;
//市数组
@property NSArray *arrCity;
//区数组
@property NSArray *arrDistrict;
//被选择的城市及码
@property NSMutableDictionary *dicSelectCityAndCityCode;
//选择器
@property (strong, nonatomic) UIPickerView *cityPicker;
//显示的城市
@property (strong, nonatomic) UILabel *btnSelectShow;

//背景图
@property(nonatomic,strong)UIView *vBg;
//工具栏视图
@property(nonatomic,strong) UIView *viewTool;
//确定按钮
@property(nonatomic,strong)UIButton *sureBtn;
//取消按钮
@property(nonatomic,strong)UIButton *cancleBtn;
//确定按钮宽度
@property(nonatomic,assign)CGFloat sureBtn_wid;
//取消按钮宽度
@property(nonatomic,assign)CGFloat cancleBtn_wid;
//第一列标签
@property(nonatomic,strong)UILabel *componentFirLbl;
//第二列标签
@property(nonatomic,strong)UILabel *componentSecLbl;
//第三列标签
@property(nonatomic,strong)UILabel *componentThirdLbl;

@end

@implementation RattanCityPicker{
    CGFloat pickV_h;//选择器默认高度
    CGFloat toolView_h;//工具栏默认高度
    CGFloat animation_duration;//动画时间
    CGFloat button_margin;//按钮间距
    CGFloat titleLbl_margin;//标签标题间距
    CGFloat rowMax_h;//单元最大高度
}

- (instancetype)init
{
    if (self = [super init]) {
        self.frame=[UIScreen mainScreen].bounds;
        pickV_h = 216;
        toolView_h = 44;
        animation_duration = 0.5;
        button_margin = 15;
        titleLbl_margin = 5;
        rowMax_h = 40;
        //初始化视图
        [self initCityPickerView];
    }
    return self;
}
//初始化视图
- (void)initCityPickerView{
    //获取数据
    [self getCityData];
    
    //添加背景
    [self addBackgroundView];
    
    //添加工具栏
    [self initToolView];
    //一个选择器
    [self addSubview:self.cityPicker];
    //设置动画效果
    [self setViewAnimation];
    //添加显示选择器
    [self showCityPicker];
}
//设置初始动画
-(void)setViewAnimation{
    if (!_animation_dur) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [UIView animateWithDuration:animation_duration - 0.01 animations:^{
                self.viewTool.frame = CGRectMake(0, KScreenHeight-pickV_h-toolView_h, KScreenWidth, toolView_h);
            }];
        });
        //给选择器添加动画
        [Helper animationWithView:self.cityPicker duration:animation_duration];
    }
}
//初始化一个工具栏
-(void)initToolView{
    //一个工具栏
    [self addSubview:self.viewTool];
    //一个取消按钮
    [self addCancelButtonWithSuperView:self.viewTool];
    //一个确定按钮
    [self addSureButtonWithSuperView:self.viewTool];
    //一个显示城市的lab
    [self.viewTool addSubview:self.btnSelectShow];
}

//一个确定按钮
-(void)addSureButtonWithSuperView:(UIView *)view{
    
    NSString *btnSure_title = @"确定";
    UIFont *btnSure_font = [self getFont:self.sureBtn_font defaultSize:17.0];
    CGSize size = [Helper textSizeWithString:btnSure_title andFont:btnSure_font];
    CGFloat btnSure_x = KScreenWidth - size.width -button_margin - titleLbl_margin;
    CGFloat btnSure_w = KScreenWidth - btnSure_x;
    self.sureBtn_wid = btnSure_w;
    UIButton *btnSure=[[UIButton alloc] initWithFrame:CGRectMake(btnSure_x, 0, btnSure_w, toolView_h)];
    [btnSure setTitle:@"确定" forState:UIControlStateNormal];
    [btnSure setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btnSure setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
    btnSure.titleLabel.font = btnSure_font;
    [btnSure addTarget:self action:@selector(btnSureAction) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:btnSure];
    self.sureBtn =btnSure;
}

//一个取消按钮
-(void)addCancelButtonWithSuperView:(UIView *)view{
    NSString *btnCancle_title = @"取消";
    UIFont *btnCancle_font = [self getFont:self.cancleBtn_font defaultSize:17.0];
    
    CGSize size = [Helper textSizeWithString:btnCancle_title andFont:btnCancle_font];
    CGFloat btnCancle_w = size.width + button_margin + titleLbl_margin;
    self.cancleBtn_wid = btnCancle_w;
    CGFloat btnCancle_x = view.frame.origin.x;
    UIButton *btnCancel=[[UIButton alloc] initWithFrame:CGRectMake(btnCancle_x, 0, btnCancle_w, toolView_h)];
    
    
    [btnCancel setTitle:btnCancle_title forState:UIControlStateNormal];
    [btnCancel setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btnCancel setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
    btnCancel.titleLabel.font = btnCancle_font;
    [btnCancel addTarget:self action:@selector(btnCancelAction) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:btnCancel];
    self.cancleBtn = btnCancel;
}

//添加背景
-(void)addBackgroundView{
    UIView *vBg = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    vBg.backgroundColor = [UIColor blackColor];
    vBg.alpha = 0.3;
    [self addSubview:vBg];
    self.vBg = vBg;
}

// 获取数据
- (void)getCityData{
    NSBundle *bundle = [NSBundle mainBundle];
    NSString *plistPath = [bundle pathForResource:@"address" ofType:@"plist"];
    NSDictionary*addressDic = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
    
    _arrProvince=[addressDic objectForKey:@"address"];
    _arrCity=[[_arrProvince objectAtIndex:0] objectForKey:@"sub"];
    _arrDistrict=[[_arrCity objectAtIndex:0] objectForKey:@"sub"];
    _dicSelectCityAndCityCode=[[NSMutableDictionary alloc] init];
    
    [_dicSelectCityAndCityCode setObject:[[_arrProvince objectAtIndex:0] objectForKey:@"name"] forKey:@"Province"];
    
    [_dicSelectCityAndCityCode setObject:[[_arrCity objectAtIndex:0] objectForKey:@"name"] forKey:@"City"];
    
    [_dicSelectCityAndCityCode setObject:[_arrDistrict objectAtIndex:0] forKey:@"District"];
    
    [_dicSelectCityAndCityCode setObject:[[[[_arrProvince objectAtIndex:0] objectForKey:@"sub"] objectAtIndex:0] objectForKey:@"zipcode"] forKey:@"cityCode"];
    
    
    _btnSelectShow.text=[_dicSelectCityAndCityCode objectForKey:@"City"];
    
}

#pragma mark-
#pragma mark- 选择器的数据源代理
//分区
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 3;
}
//每个区的行数
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if (component == PROVINCE_COMPONENT) {//省
        return [_arrProvince count];
    }else if (component == CITY_COMPONENT) {//市
        return [_arrCity count];
    }else {//区
        return [_arrDistrict count];
    }
}

#pragma mark-
#pragma mark- 选择器的代理方法
//使用城市的名称作为title
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if (component == PROVINCE_COMPONENT) {
        return [[_arrProvince objectAtIndex: row] objectForKey:@"name"];
    }else if (component == CITY_COMPONENT) {
        return [[_arrCity objectAtIndex: row] objectForKey:@"name"];
    }else {
        return [_arrDistrict objectAtIndex: row];
    }
}


- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if (component == PROVINCE_COMPONENT) {
        _arrCity=[[_arrProvince objectAtIndex:row] objectForKey:@"sub"];
        //大于0就不是直辖市，而是省份，可以分三组。直辖市就直接把城市数组给区域数组
        if (_arrCity.count>0) {
            _arrDistrict=[[_arrCity objectAtIndex:0] objectForKey:@"sub"];
        }else{
            _arrDistrict=_arrCity;
        }
        
        [_dicSelectCityAndCityCode setObject:[[_arrProvince objectAtIndex:row] objectForKey:@"name"] forKey:@"Province"];
        [_dicSelectCityAndCityCode setObject:[[[[_arrProvince objectAtIndex:row] objectForKey:@"sub"] objectAtIndex:0] objectForKey:@"zipcode"] forKey:@"cityCode"];
        [_dicSelectCityAndCityCode setObject:[[_arrCity objectAtIndex:0] objectForKey:@"name"] forKey:@"City"];
        [_dicSelectCityAndCityCode setObject:[_arrDistrict objectAtIndex:0] forKey:@"District"];
        
        
        [_cityPicker selectRow: 0 inComponent: CITY_COMPONENT animated: YES];
        [_cityPicker selectRow: 0 inComponent: DISTRICT_COMPONENT animated: YES];
        [_cityPicker reloadComponent: CITY_COMPONENT];
        [_cityPicker reloadComponent: DISTRICT_COMPONENT];
    }else if (component == CITY_COMPONENT) {
        if (_arrCity.count>0) {
            _arrDistrict=[[_arrCity objectAtIndex:row] objectForKey:@"sub"];
        }
        
        [_dicSelectCityAndCityCode setObject:[[_arrCity objectAtIndex:row] objectForKey:@"name"] forKey:@"City"];
        [_dicSelectCityAndCityCode setObject:[_arrDistrict objectAtIndex:0] forKey:@"District"];
        [_dicSelectCityAndCityCode setObject:[[_arrCity objectAtIndex:row] objectForKey:@"zipcode"] forKey:@"cityCode"];
        
        [_cityPicker selectRow: 0 inComponent: DISTRICT_COMPONENT animated: YES];
        [_cityPicker reloadComponent: DISTRICT_COMPONENT];
    }else{
        [_dicSelectCityAndCityCode setObject:[_arrDistrict objectAtIndex:row] forKey:@"District"];
    }
    _btnSelectShow.text=[_dicSelectCityAndCityCode objectForKey:@"City"];
}

- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
{
    return KScreenWidth/3.0;
}

- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{
    return rowMax_h;
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
    
    UIColor *defBg_color = [UIColor clearColor];
    UIColor *defTitle_color = [UIColor blackColor];
    if (component == PROVINCE_COMPONENT) {
        UILabel *firLbl = [[UILabel alloc] init];
        firLbl.textAlignment = 1;
        firLbl.text = [[_arrProvince objectAtIndex:row] objectForKey:@"name"];
        firLbl.numberOfLines = 2;
        UIFont *font = [self getFont:self.componentFir_font defaultSize:14.0];
        firLbl.font = font;
        firLbl.frame = CGRectMake(0.0, 0.0, KScreenWidth/3.0, rowMax_h);
        firLbl.backgroundColor =self.componentBgFir_color?:defBg_color;
        firLbl.textColor = self.componentStrFir_color?:defTitle_color;
        self.componentFirLbl = firLbl;
        return self.componentFirLbl;
    }else if (component == CITY_COMPONENT) {
        UILabel *secLbl = [[UILabel alloc] init];
        secLbl.textAlignment = 1;
        secLbl.text = [[_arrCity objectAtIndex:row] objectForKey:@"name"];
        secLbl.numberOfLines = 2;
        UIFont *font = [self getFont:self.componentSec_font defaultSize:14.0];
        secLbl.font = font;
        secLbl.frame = CGRectMake(0.0, 0.0, KScreenWidth/3.0, rowMax_h);
        
        secLbl.backgroundColor = self.componentBgSec_color?:defBg_color;
        secLbl.textColor = self.componentStrSec_color?:defTitle_color;
        self.componentSecLbl = secLbl;
        return self.componentSecLbl;
    }else {
        UILabel *thirdLbl = [[UILabel alloc] init];
        thirdLbl.textAlignment = 1;
        thirdLbl.text = [_arrDistrict objectAtIndex:row];
        thirdLbl.numberOfLines = 2;
        UIFont *font = [self getFont:self.componentThird_font defaultSize:14.0];
        thirdLbl.font = font;
        thirdLbl.frame = CGRectMake(0.0, 0.0, KScreenWidth/3.0, rowMax_h);
        
        thirdLbl.backgroundColor = self.componentBgThird_color?:defBg_color;
        thirdLbl.textColor = self.componentStrThird_color?:defTitle_color;
        self.componentThirdLbl = thirdLbl;
        return self.componentThirdLbl;
    }
}

#pragma mark -block获取选择的城市词典
- (void)cityPickerSetSelectCity{
    if (_getSelectCity) {
        _getSelectCity(_dicSelectCityAndCityCode);
    }
}

- (void)cityPikerGetSelectCity:(GetSelectCity)getSelectCity{
    _getSelectCity=getSelectCity;
}

//取消按钮
- (void)btnCancelAction{
    [self disMissCityPicker];
    if (_cancelBtnBlock) {
        _cancelBtnBlock();
    }
}
//确定按钮
- (void)btnSureAction{
    [self cityPickerSetSelectCity];
    [self disMissCityPicker];
    if (_sureBtnBlock) {
        _sureBtnBlock();
    }
}

//添加控件
- (void)showCityPicker{
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    self.center = [UIApplication sharedApplication].keyWindow.center;
}
//移除控件
-(void)disMissCityPicker{
    [self removeFromSuperview];
}


#pragma mark -
#pragma mark - Setter
//背景视图属性
-(void)setVBG_color:(UIColor *)vBG_color{
    self.vBg.backgroundColor = vBG_color;
    _vBG_color = vBG_color;
}

-(void)setVBG_alpha:(CGFloat)vBG_alpha{
    self.vBg.alpha = vBG_alpha;
    _vBG_alpha = vBG_alpha;
}
//按钮属性
-(void)setSureBtn_font:(UIFont *)sureBtn_font{
    self.sureBtn.titleLabel.font = sureBtn_font;
    _sureBtn_font = sureBtn_font;
}
-(void)setSureBtnBg_color:(UIColor *)sureBtnBg_color{
    self.sureBtn.backgroundColor = sureBtnBg_color;
    _sureBtnBg_color = sureBtnBg_color;
}
-(void)setSureBtnNor_color:(UIColor *)sureBtnNor_color{
    [self.sureBtn setTitleColor:sureBtnNor_color forState:UIControlStateNormal];
    _sureBtnNor_color = sureBtnNor_color;
}
-(void)setSureBtnHigl_color:(UIColor *)sureBtnHigl_color{
    [self.sureBtn setTitleColor:sureBtnHigl_color forState:UIControlStateHighlighted];
    _sureBtnHigl_color = sureBtnHigl_color;
}

-(void)setCancleBtn_font:(UIFont *)cancleBtn_font{
    self.cancleBtn.titleLabel.font = cancleBtn_font;
    _cancleBtn_font = cancleBtn_font;
}
-(void)setCancleBtnBg_color:(UIColor *)cancleBtnBg_color{
    self.cancleBtn.backgroundColor = cancleBtnBg_color;
    _cancleBtnBg_color = cancleBtnBg_color;
}
-(void)setCancleBtnNor_color:(UIColor *)cancleBtnNor_color{
    [self.cancleBtn setTitleColor:cancleBtnNor_color forState:UIControlStateNormal];
    _cancleBtnNor_color = cancleBtnNor_color;
}
-(void)setCancleBtnHigl_color:(UIColor *)cancleBtnHigl_color{
    [self.cancleBtn setTitleColor:cancleBtnHigl_color forState:UIControlStateHighlighted];
    _cancleBtnHigl_color = cancleBtnHigl_color;
}

-(void)setToolV_h:(CGFloat)toolV_h{
    CGRect frame = self.viewTool.frame;
    frame.size.height = toolV_h;
    self.viewTool.frame = frame;
    _toolV_h = toolV_h;
}

-(void)setToolViewBg_color:(UIColor *)toolViewBg_color{
    self.viewTool.backgroundColor = toolViewBg_color;
    _toolViewBg_color = toolViewBg_color;
}

-(void)setPickView_h:(CGFloat)pickView_h{
    pickV_h = pickView_h;
    self.cityPicker.frame = CGRectMake(0, KScreenHeight-pickV_h, KScreenWidth, pickV_h);
    
    _pickView_h = pickView_h;
}

-(void)setAnimation_dur:(CGFloat)animation_dur{
    animation_duration = animation_dur;
    //添加工具栏
    [self setViewAnimation];
    _animation_dur = animation_dur;
}

-(void)setCancleBtn_Title:(NSString *)cancleBtn_Title{
    [self.cancleBtn setTitle:cancleBtn_Title forState:UIControlStateNormal];
    UIFont *cancle_font = [self getFont:self.cancleBtn_font defaultSize:17.0];
    CGSize cancleBtn_size = [Helper textSizeWithString:cancleBtn_Title andFont:cancle_font];
    
    //取消按钮
    CGRect frameCancle = self.cancleBtn.frame;
    frameCancle.size.width = cancleBtn_size.width + button_margin + titleLbl_margin;
    self.cancleBtn.frame = frameCancle;
    
    //显示城市标签
    CGRect frameLblShow = self.btnSelectShow.frame;
    CGFloat lbl_x = frameCancle.size.width;
    CGFloat lbl_w = KScreenWidth - lbl_x - self.sureBtn_wid;
    frameLblShow.origin.x = lbl_x;
    frameLblShow.size.width = lbl_w;
    self.btnSelectShow.frame = frameLblShow;
    
    _cancleBtn_Title = cancleBtn_Title;
}

-(void)setSureBtn_Title:(NSString *)sureBtn_Title{
    [self.sureBtn setTitle:sureBtn_Title forState:UIControlStateNormal];
    UIFont *sure_font = [self getFont:self.sureBtn_font defaultSize:17.0];
    CGSize sure_size = [Helper textSizeWithString:sureBtn_Title andFont:sure_font];
    
    //确认按钮
    CGRect frameSureBtn = self.sureBtn.frame;
    CGFloat btnSure_x = KScreenWidth - sure_size.width -button_margin - titleLbl_margin;
    CGFloat btnSure_w = KScreenWidth - btnSure_x;
    frameSureBtn.origin.x = btnSure_x;
    frameSureBtn.size.width = btnSure_w;
    self.sureBtn.frame = frameSureBtn;
    
    //显示城市标签
    CGRect frameLblShow = self.btnSelectShow.frame;
    CGFloat lbl_x = frameSureBtn.size.width;
    CGFloat lbl_w = KScreenWidth - self.cancleBtn_wid - btnSure_w;
    frameLblShow.origin.x = lbl_x;
    frameLblShow.size.width = lbl_w;
    self.btnSelectShow.frame = frameLblShow;
    
    _sureBtn_Title = sureBtn_Title;
}

-(void)setBtn_margin:(CGFloat)btn_margin{
    CGFloat titleLbl_mar = [self getSelectLblMargin];
    //取消按钮
    CGRect frameCancle = self.cancleBtn.frame;
    
    CGFloat cancleBtnStr_w = [self getCancelBtnWidth:self.cancleBtn_Title].width;
    
    frameCancle.size.width = cancleBtnStr_w + btn_margin + titleLbl_mar;
    self.cancleBtn.frame = frameCancle;
    
    //确认按钮
    CGRect frameSureBtn = self.sureBtn.frame;
    
    CGFloat sureStr_w = [self getSureBtnWidth:self.sureBtn_Title].width;
    
    CGFloat btnSure_x = KScreenWidth - sureStr_w - btn_margin - titleLbl_mar;
    CGFloat btnSure_w = KScreenWidth - btnSure_x;
    frameSureBtn.origin.x = btnSure_x;
    frameSureBtn.size.width = btnSure_w;
    self.sureBtn.frame = frameSureBtn;
    
    //显示城市标签
    CGRect frameLblShow = self.btnSelectShow.frame;
    CGFloat lbl_x = frameSureBtn.size.width;
    CGFloat lbl_w = KScreenWidth - frameCancle.size.width - btnSure_w;
    frameLblShow.origin.x = lbl_x;
    frameLblShow.size.width = lbl_w;
    self.btnSelectShow.frame = frameLblShow;
    
    _btn_margin = btn_margin;
    
}

#pragma mark - 选择标签属性
-(void)setSelectLbl_margin:(CGFloat)selectLbl_margin{
    CGFloat sureStr_w = [self getSureBtnWidth:self.sureBtn_Title].width;
    CGFloat cancleStr_w = [self getSureBtnWidth:self.cancleBtn_Title].width;
    CGFloat btn_margin = [self getBtnMargin];
    
    //取消按钮
    CGRect frameCancle = self.cancleBtn.frame;
    frameCancle.size.width = cancleStr_w + selectLbl_margin + btn_margin;
    self.cancleBtn.frame = frameCancle;
    
    //确认按钮
    CGRect frameSureBtn = self.sureBtn.frame;
    CGFloat btnSure_x = KScreenWidth - sureStr_w - selectLbl_margin - btn_margin;
    CGFloat btnSure_w = KScreenWidth - btnSure_x;
    frameSureBtn.origin.x = btnSure_x;
    frameSureBtn.size.width = btnSure_w;
    self.sureBtn.frame = frameSureBtn;
    
    //显示城市标签
    CGRect frameLblShow = self.btnSelectShow.frame;
    CGFloat lbl_x = frameSureBtn.size.width;
    CGFloat lbl_w = KScreenWidth - frameCancle.size.width - btnSure_w;
    frameLblShow.origin.x = lbl_x;
    frameLblShow.size.width = lbl_w;
    self.btnSelectShow.frame = frameLblShow;
    
    _selectLbl_margin = selectLbl_margin;
}

-(void)setSelectLblBg_color:(UIColor *)selectLblBg_color{
    self.btnSelectShow.backgroundColor = selectLblBg_color;
    _selectLblBg_color = selectLblBg_color;
}
-(void)setSelectLblStr_color:(UIColor *)selectLblStr_color{
    self.btnSelectShow.textColor = selectLblStr_color;
    _selectLblStr_color = selectLblStr_color;
}
-(void)setSelectLblStr_font:(UIFont *)selectLblStr_font{
    self.btnSelectShow.font = selectLblStr_font;
    _selectLblStr_font = selectLblStr_font;
}

#pragma mark - 选择器设置
//选择器背景色
-(void)setPickViewBg_color:(UIColor *)pickViewBg_color{
    self.cityPicker.backgroundColor = pickViewBg_color;
    _pickViewBg_color = pickViewBg_color;
}
//第一列字体大小
-(void)setComponentFir_font:(UIFont *)componentFir_font{
    self.componentFirLbl.font = componentFir_font;
    [self.cityPicker reloadAllComponents];
    _componentFir_font = componentFir_font;
}
//字体颜色
-(void)setComponentStrFir_color:(UIColor *)componentStrFir_color{
    self.componentFirLbl.textColor = componentStrFir_color;
    [self.cityPicker reloadAllComponents];
    _componentStrFir_color = componentStrFir_color;
}
//背景色
-(void)setComponentBgFir_color:(UIColor *)componentBgFir_color{
    self.componentFirLbl.backgroundColor = componentBgFir_color;
    [self.cityPicker reloadAllComponents];
    _componentBgFir_color = componentBgFir_color;
}

//第二列
-(void)setComponentSec_font:(UIFont *)componentSec_font{
    self.componentSecLbl.font = componentSec_font;
    [self.cityPicker reloadAllComponents];
    _componentSec_font = componentSec_font;
}

-(void)setComponentBgSec_color:(UIColor *)componentBgSec_color{
    self.componentSecLbl.backgroundColor = componentBgSec_color;
    [self.cityPicker reloadAllComponents];
    _componentBgSec_color = componentBgSec_color;
}
-(void)setComponentStrSec_color:(UIColor *)componentStrSec_color{
    self.componentSecLbl.textColor = componentStrSec_color;
    [self.cityPicker reloadAllComponents];
    _componentStrSec_color = componentStrSec_color;
    
}
//第三列
-(void)setComponentThird_font:(UIFont *)componentThird_font{
    self.componentThirdLbl.font = componentThird_font;
    [self.cityPicker reloadAllComponents];
    _componentThird_font = componentThird_font;
}

-(void)setComponentBgThird_color:(UIColor *)componentBgThird_color{
    self.componentThirdLbl.backgroundColor = componentBgThird_color;
    [self.cityPicker reloadAllComponents];
    _componentBgThird_color = componentBgThird_color;
}
-(void)setComponentStrThird_color:(UIColor *)componentStrThird_color{
    self.componentThirdLbl.textColor = componentStrThird_color;
    [self.cityPicker reloadAllComponents];
    _componentStrThird_color = componentStrThird_color;
}

#pragma mark -
#pragma mark - Getter

//工具栏
-(UIView *)viewTool{
    if (!_viewTool) {
        UIView *viewTool=[[UIView alloc] init];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            CGFloat viewTool_h = 0;
            if (self.animation_dur < 0.3) {
                viewTool_h = KScreenHeight-pickV_h-toolView_h;
            }
            viewTool.frame = CGRectMake(0, viewTool_h, KScreenWidth, toolView_h);
        });
        UIColor *color=[UIColor colorWithRed:230/256.0 green:230/256.0 blue:230/256.0 alpha:1];
        viewTool.backgroundColor=color;
        _viewTool = viewTool;
    }
    return _viewTool;
}

//设置显示城市标签
-(UILabel *)btnSelectShow{
    if (!_btnSelectShow) {
        CGFloat lbl_x = self.cancleBtn_wid;
        CGFloat lbl_w = KScreenWidth - lbl_x - self.sureBtn_wid;
        UILabel *btnSelectShow =[[UILabel alloc] initWithFrame:CGRectMake(lbl_x,0,lbl_w, toolView_h)];
        btnSelectShow.text=@"北京市";
        btnSelectShow.textAlignment=1;
        _btnSelectShow = btnSelectShow;
    }
    return _btnSelectShow;
}

//选择器
-(UIPickerView *)cityPicker{
    if (!_cityPicker) {
        UIPickerView *pickerView=[[UIPickerView alloc] initWithFrame:CGRectMake(0, KScreenHeight-pickV_h, KScreenWidth, pickV_h)];
        pickerView.backgroundColor = [UIColor whiteColor];
        pickerView.delegate=self;
        pickerView.dataSource=self;
        _cityPicker = pickerView;
    }
    return _cityPicker;
}

-(UIFont *)getFont:(UIFont *)font defaultSize:(CGFloat)fontSize{
    UIFont *fontSet = font?font:[UIFont systemFontOfSize:fontSize];
    return fontSet;
}

-(CGSize)getCancelBtnWidth:(NSString *)str{
    NSString *cancle_str = str?str:@"取消";
    UIFont *font = [self getFont:self.cancleBtn_font defaultSize:17.0];
    CGSize cancleStr_size = [Helper textSizeWithString:cancle_str andFont:font];
    return cancleStr_size;
}

-(CGSize)getSureBtnWidth:(NSString *)str{
    NSString *sure_str = str?str:@"确认";
    UIFont *font = [self getFont:self.sureBtn_font defaultSize:17.0];
    CGSize sureStr_size = [Helper textSizeWithString:sure_str andFont:font];
    return sureStr_size;
}

-(CGFloat)getSelectLblMargin{
    CGFloat selectLbl_mar = self.selectLbl_margin?:titleLbl_margin;
    return selectLbl_mar;
}

-(CGFloat)getBtnMargin{
    CGFloat btnMargin = self.btn_margin?:button_margin;
    return btnMargin;
}

@end
